package icu.sunway.gushenBlogBackEnd.Controller;

import icu.sunway.gushenBlogBackEnd.Entity.View.ResultVO;
import icu.sunway.gushenBlogBackEnd.Service.FileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@CrossOrigin
@RestController
@RequestMapping("/api/file")
public class FileController {
    final FileService fileService;

    public FileController(FileService fileService) {
        this.fileService = fileService;
    }

    @PostMapping("/upload_avatar")
    public ResultVO<String> uploadAvatar(@RequestPart("file") MultipartFile file) {
        return fileService.upload(file, "avatars");
    }

    @PostMapping("/upload_blogImage")
    public ResultVO<String> uploadBlogImages(@RequestPart("file") MultipartFile file) {
        return fileService.upload(file, "blogImages");
    }
}
